var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("Util"),
    l = cc._decorator,
    d = l.ccclass,
    u = l.property,
    p = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.node_head = null),
                (t.node_tail = null),
                (t.nodes_body = []),
                (t.swayUnitTime = 0.5),
                (t.swayDis = 20),
                (t.swayFrequency = 0.2),
                (t.initAngle = 10),
                (t.angleAdd = 8),
                (t.initHeadAngle = 0),
                (t.initBodyInitAngles = []),
                (t.initBodyPositions = []),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.init = function () {
                this.swayDis *= this.node.scale;
                for (var e = 0; e < this.nodes_body.length; e++)
                    (this.initBodyPositions[e] = this.nodes_body[e].position.clone()),
                        (this.initBodyPositions[e].x = 0),
                        (this.initBodyPositions[e].y = this.node_head.y + 35 * (e + 1)),
                        (this.initBodyInitAngles[e] = this.nodes_body[e].angle);
                (this.node_tail.x = 0),
                    (this.node_tail.angle = 0),
                    (this.node_tail.y = this.node_head.y + 35 * (this.nodes_body.length + 1));
            }),
            (t.prototype.initAndStart = function () {
                this.init(), this.startAction();
            }),
            (t.prototype.startAction = function () {
                var e = this;
                this.stopAction(),
                    this.scheduleOnce(function () {
                        e.headActive();
                        for (var t = 0; t < e.nodes_body.length; t++) e.bodyActive(t);
                        e.tailActive();
                    });
            }),
            (t.prototype.stopAction = function () {
                this.unscheduleAllCallbacks(),
                    cc.Tween.stopAllByTarget(this.node_head),
                    (this.node_head.angle = this.initHeadAngle);
                for (var e = 0; e < this.nodes_body.length; e++)
                    cc.Tween.stopAllByTarget(this.nodes_body[e]),
                        (this.nodes_body[e].position = this.initBodyPositions[e].clone()),
                        (this.nodes_body[e].angle = this.initBodyInitAngles[e]);
                cc.Tween.stopAllByTarget(this.node_tail),
                    (this.node_tail.x = 0),
                    (this.node_tail.angle = 0),
                    (this.node_tail.y = this.node_head.y + 35 * (this.nodes_body.length + 1));
            }),
            (t.prototype.setSkin = function (e) {
                this.node_head.getComponent(cc.Sprite).spriteFrame = c.default.getGameBundleSpriteFrame(
                    s.default.GameBundle.textures.assetsList[e + "_head_0"]
                );
                for (var t = 1, o = 0; o < this.nodes_body.length; o++)
                    (this.nodes_body[o].getComponent(cc.Sprite).spriteFrame = c.default.getGameBundleSpriteFrame(
                        s.default.GameBundle.textures.assetsList[e + "_body_" + t]
                    )),
                        (t = 1 === t ? 2 : 1);
                this.node_tail.getChildByName("tail").getComponent(cc.Sprite).spriteFrame =
                    c.default.getGameBundleSpriteFrame(s.default.GameBundle.textures.assetsList[e + "_tail"]);
            }),
            (t.prototype.setDecorate = function (e) {
                if (-1 !== e) {
                    var t = cc.v3(0, 120);
                    4 === e && (t.y = 120);
                    var o = this.node_head.getChildByName("decorate_icon");
                    o &&
                        ((o.getComponent(cc.Sprite).spriteFrame = c.default.getGameBundleSpriteFrame(
                            s.default.GameBundle.textures.assetsList["decorate_icon_" + e]
                        )),
                        (o.position = t));
                }
            }),
            (t.prototype.headActive = function () {
                var e = cc.tween().to(this.swayUnitTime, {angle: this.initAngle}),
                    t = cc.tween().to(this.swayUnitTime, {angle: -this.initAngle}),
                    o = cc.tween().sequence(e, t);
                cc.tween(this.node_head).repeatForever(o).start();
            }),
            (t.prototype.bodyActive = function (e) {
                var t = this;
                this.scheduleOnce(function () {
                    var o = t.swayDis,
                        n = cc
                            .tween()
                            .parallel(
                                cc.tween().to(t.swayUnitTime, {x: -o}),
                                cc.tween().to(t.swayUnitTime, {angle: t.initAngle + t.angleAdd * e})
                            ),
                        i = cc
                            .tween()
                            .parallel(
                                cc.tween().to(t.swayUnitTime, {x: o}),
                                cc.tween().to(t.swayUnitTime, {angle: -(t.initAngle + t.angleAdd * e)})
                            ),
                        a = cc.tween().sequence(n, i);
                    e !== t.nodes_body.length
                        ? cc.tween(t.nodes_body[e]).repeatForever(a).start()
                        : cc.tween(t.node_tail).repeatForever(a).start();
                }, e * this.swayFrequency);
            }),
            (t.prototype.tailActive = function () {
                this.bodyActive(this.nodes_body.length);
            }),
            r([u(cc.Node)], t.prototype, "node_head", void 0),
            r([u(cc.Node)], t.prototype, "node_tail", void 0),
            r([u([cc.Node])], t.prototype, "nodes_body", void 0),
            r([d], t)
        );
    })(cc.Component);
i.default = p;
